package com.strato.base.aop.v1_0_0.inline;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import com.strato.base.aop.v1_0_0.Invocation;
import com.strato.base.aop.v1_0_0.InvocationInterceptor;
import com.strato.base.aop.v1_0_0.advice.Advice;

public class DelegateMethodInterceptor implements MethodInterceptor {

	private InvocationInterceptor interceptor;

	public DelegateMethodInterceptor(InvocationInterceptor interceptor) {
		this.interceptor=interceptor;
	}

	@Override
	public final Object intercept(Object o, Method method, Object[] args,
			MethodProxy proxy) throws Throwable {
		if(Advice.class.isInstance(o)){
			return proxy.invokeSuper(o, args);
		}
		Invocation invocation=new CGLibInvocation(o, method, args, proxy);
		return interceptor.intercept(invocation);
	}

}
